<%@ page import="com.ws.ssmzongjie3.util.Res" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>线路列表</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/bootstrap/js/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.min.js"></script>
    <style>
        /* 表单样式优化 */
        .form-inline .form-group {
            margin-right: 10px;
            margin-bottom: 10px;
        }
        .form-inline .form-control {
            width: auto;
            display: inline-block;
        }
        /* 表格样式优化 */
        .table {
            font-size: 14px;
            margin-top: 20px;
        }
        .table th, .table td {
            padding: 8px;
            text-align: center;
        }
        .table img {
            max-width: 100px;
            height: auto;
        }
        /* 分页导航样式优化 */
        .pagination {
            margin: 20px 0;
        }
        .pagination .page-item.active .page-link {
            background-color: #007bff;
            border-color: #007bff;
        }
        .pagination .page-link {
            color: #007bff;
        }
        /* 按钮样式优化 */
        .btn {
            margin-right: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>线路列表</h1>

        <div class="row">
            <div class="col-md-12">
                <!-- 多条件搜索表单 -->
                <form class="form-inline mb-3" action="list" method="get">
                    <div class="form-group mr-2">
                        <input type="text" name="route_name" class="form-control" placeholder="线路名称" value="${param.route_name}">
                    </div>
                    <div class="form-group mr-2">
                        <input type="text" name="route_start_place" class="form-control" placeholder="出发地" value="${param.route_start_place}">
                    </div>
                    <div class="form-group mr-2">
                        <input type="text" name="route_end_place" class="form-control" placeholder="目的地" value="${param.route_end_place}">
                    </div>
                    <div class="form-group mr-2">
                        <select name="route_type" class="form-control">
                            <option value="">全部类型</option>
                            <c:forEach items="${routeTypeList}" var="routeType">
                                <option value="${routeType.route_type}" <c:if test="${param.route_type == routeType.route_type}">selected</c:if>>${routeType.route_type}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="form-group mr-2">
                        <select name="is_delete" class="form-control">
                            <option value="">全部状态</option>
                            <option value="0" <c:if test="${param.is_delete == '0'}">selected</c:if>>正常</option>
                            <option value="1" <c:if test="${param.is_delete == '1'}">selected</c:if>>停用</option>
                        </select>
                    </div>
                    <button type="submit" class="btn btn-primary">搜索</button>
                </form>
                <a href="add" class="btn btn-success">添加新线路</a>

                <table class="table table-bordered clearfix" id="houuser-list">
                    <thead>
                        <tr class="bg-primary">
                            <th>线路ID</th>
                            <th>线路名称</th>
                            <th>线路出发地</th>
                            <th>线路目的地</th>
                            <th>线路价格</th>
                            <th>线路天数</th>
                            <th>线路主图</th>
                            <th>线路类型</th>
                            <th>线路是否特价</th>
                            <th>线路销量</th>
                            <th>线路是否推荐</th>
                            <th>线路商家</th>
                            <th>线路点赞数</th>
                            <th>线路收藏数</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <c:forEach items="${pageInfo.list}" var="route">
                            <tr>
                                <td>${route.route_id}</td>
                                <td>${route.route_name}</td>
                                <td>${route.route_start_place}</td>
                                <td>${route.route_end_place}</td>
                                <td>${route.route_price}</td>
                                <td>${route.route_day}</td>
                                <td><img src="<%=Res.fileUrl%>${route.route_photo}" width="50" height="50" alt="轮播图"></td>
                                <td>${route.columns.column_name}</td>
                                <td>
                                    <c:choose>
                                        <c:when test="${route.route_special == 0}">是</c:when>
                                        <c:otherwise>否</c:otherwise>
                                    </c:choose>
                                </td>
                                <td>${route.sales}</td>
                                <td>
                                    <c:choose>
                                        <c:when test="${route.recommend == 0}">是</c:when>
                                        <c:otherwise>否</c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                    ${route.business.business_name}
                                </td>
                                    <td>${route.like_count}</td>
                                    <td>${route.collection_count}</td>
                                
                                <td>
                            <c:choose>
                                <c:when test="${houuser.sid == 0}">
                                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/route/huixian?route_id=${route.route_id}">编辑</a>
                                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/route/delete?route_id=${route.route_id}">删除</a>
                                    <p></p>
                                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/lunbotu/add?route_id=${route.route_id}&route_name=${route.route_name}">添加轮播图</a>
                                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/route_map/add?route_id=${route.route_id}">添加附图</a>
                                </c:when>
                                <c:when test="${houuser.sid == route.business.business_id}">
                                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/route/huixian?route_id=${route.route_id}">编辑</a>
                                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/route/delete?route_id=${route.route_id}">删除</a>
                                    <p></p>
                                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/lunbotu/add?route_id=${route.route_id}&route_name=${route.route_name}">添加轮播图</a>
                                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/route_map/add?route_id=${route.route_id}">添加附图</a>
                                </c:when>
                            </c:choose>
                                </td>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>

                <!-- 分页导航 -->
                <div style="text-align: center;">
                    <nav aria-label="Page navigation" style="display: inline-block;">
                        <c:set var="startPage" value="${pageInfo.pageNum - 4}" />
                        <c:if test="${startPage < 1}">
                            <c:set var="startPage" value="1" />
                        </c:if>
                        <c:set var="endPage" value="${startPage + 9}" />
                        <c:if test="${endPage > pageInfo.pages}">
                            <c:set var="endPage" value="${pageInfo.pages}" />
                            <c:if test="${endPage - startPage + 1 < 10}">
                                <c:set var="startPage" value="${endPage - 9}" />
                                <c:if test="${startPage < 1}">
                                    <c:set var="startPage" value="1" />
                                </c:if>
                            </c:if>
                        </c:if>

                        <ul class="pagination">
                            <li class="${pageInfo.pageNum == 1 ? 'disabled' : ''}">
                                <a href="list?currentPage=1&pageSize=${pageInfo.pageSize}&route_name=${param.route_name}&route_start_place=${param.route_start_place}&route_end_place=${param.route_end_place}&route_type=${param.route_type}&is_delete=${param.is_delete}" aria-label="First">
                                    <span aria-hidden="true">首页</span>
                                </a>
                            </li>
                            <li class="${pageInfo.pageNum == 1 ? 'disabled' : ''}">
                                <a href="list?currentPage=${pageInfo.pageNum - 1 > 0 ? pageInfo.pageNum - 1 : 1}&pageSize=${pageInfo.pageSize}&route_name=${param.route_name}&route_start_place=${param.route_start_place}&route_end_place=${param.route_end_place}&route_type=${param.route_type}&is_delete=${param.is_delete}" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                            <c:forEach begin="${startPage}" end="${endPage}" var="i">
                                <li class="${i == pageInfo.pageNum ? 'active' : ''}">
                                    <a href="list?currentPage=${i}&pageSize=${pageInfo.pageSize}&route_name=${param.route_name}&route_start_place=${param.route_start_place}&route_end_place=${param.route_end_place}&route_type=${param.route_type}&is_delete=${param.is_delete}">${i}</a>
                                </li>
                            </c:forEach>
                            <li class="${pageInfo.pageNum == pageInfo.pages ? 'disabled' : ''}">
                                <a href="list?currentPage=${pageInfo.pageNum + 1}&pageSize=${pageInfo.pageSize}&route_name=${param.route_name}&route_start_place=${param.route_start_place}&route_end_place=${param.route_end_place}&route_type=${param.route_type}&is_delete=${param.is_delete}" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                            <li class="${pageInfo.pageNum == pageInfo.pages ? 'disabled' : ''}">
                                <a href="list?currentPage=${pageInfo.pages}&pageSize=${pageInfo.pageSize}&route_name=${param.route_name}&route_start_place=${param.route_start_place}&route_end_place=${param.route_end_place}&route_type=${param.route_type}&is_delete=${param.is_delete}" aria-label="Last">
                                    <span aria-hidden="true">尾页</span>
                                </a>
                            </li>
                        </ul>
                    </nav>
                    <div style="margin-top: 10px;">
                        <span>当前第${pageInfo.pageNum}页/共${pageInfo.pages}页，共${pageInfo.total}条数据</span>
                        每页显示
                        <select name="pageSize" onchange="changePageSize(this.value)">
                            <option value="5" <c:if test="${pageInfo.pageSize == 5}">selected</c:if>>5</option>
                            <option value="10" <c:if test="${pageInfo.pageSize == 10}">selected</c:if>>10</option>
                            <option value="15" <c:if test="${pageInfo.pageSize == 15}">selected</c:if>>15</option>
                            <option value="20" <c:if test="${pageInfo.pageSize == 20}">selected</c:if>>20</option>
                        </select>条数据
                    </div>
                </div>
                <script>
                function changePageSize(pageSize) {
                    var currentPage = ${pageInfo.pageNum};
                    var routeName = "${param.route_name}";
                    var startPlace = "${param.route_start_place}";
                    var endPlace = "${param.route_end_place}";
                    var routeType = "${param.route_type}";
                    var isDelete = "${param.is_delete}";
                    var url = "list?currentPage=" + currentPage + "&pageSize=" + pageSize +
                              "&route_name=" + encodeURIComponent(routeName) +
                              "&route_start_place=" + encodeURIComponent(startPlace) +
                              "&route_end_place=" + encodeURIComponent(endPlace) +
                              "&route_type=" + encodeURIComponent(routeType) +
                              "&is_delete=" + encodeURIComponent(isDelete);
                    window.location.href = url;
                }
                </script>

            </div>
        </div>
    </div>
</body>
</html>